<template>
    <!-- 用户管理-系统用户管理=微信绑定信息 -->
    <base-breadcrumb :title="$route.meta.title">
      <a-spin :spinning="loading">
        <!-- 搜索 -->
        <searchData :searchData="searchArr" @search="search"></searchData>
        <!-- 表格 -->
        <a-card :bordered="false">
            <!-- <title-name :title="$route.meta.title"></title-name> -->
             <div class="pub-table-select-count" style="margin: 10px 0">
          <a-icon type="info-circle" theme="twoTone" />
              <span>共计：<a>{{total || 0}}个</a>
                <!-- <a>{{ statisticsInfo.totalNum || 0 }} 个</a> -->
              </span>
            </div>
            <!-- 表格 -->
            <list-table
                ref="table"
                tableLayout="fixed"
                size="default"
                rowKey="id"
                :columns="columns"
                :request="loadData"
                :page-keys="['pageNum', 'pageSize','total']"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto">
                <template slot="action" slot-scope="text, record">
                    <a  v-btnPermission="'sy_010_bin_01'" @click="handleManage(record)">解绑</a>

                </template>
                <span   slot="type"
                    slot-scope="text, record">
                    {{getType(record.type)}}
                </span>
            </list-table>
        </a-card>
      </a-spin>
    </base-breadcrumb>
</template>

<script>
import { usersWechat,deleteUserAndWechatByUserId} from '@/api/system/wechatBindInfo' // api
import BasePage from '@/views/basePage' // 基础配置
const searchArr = [
    // 搜索框
    {name: '用户名称',type: 'input', value: 'name'},
    {name: '用户账号',type: 'input',value: 'account'},
    {
        name: '用户类型',
        value: 'type',
        type: 'select',
        data: [{value: '0',label: '公司用户'},
            {value: '1',label: '分包商'},
            {value: '2',label: '业主'}
        ]
    },
    // {name: '绑定微信openId',type: 'input',value: 'openId'},
]

const columns = [
    {title: '序号',width: 80,dataIndex: 'index',
        customRender() {
            return arguments[2] + 1
        }
    },
    {title: '用户名称',dataIndex: 'name',ellipsis: true,width: 250,},
    {title: '用户账号',dataIndex: 'userName',ellipsis: true,width: 150,},
    {title: '用户类型',dataIndex: 'type',ellipsis: true,width: 300, scopedSlots: { customRender: 'type' }},
    {title: '绑定微信openId',dataIndex: 'openId',ellipsis: true,},
    {title: '操作',dataIndex: 'action',width: '280px',align: 'center',scopedSlots: { customRender: 'action' },}
]
export default {
    name: 'wechatBindInfo' + Date.now(),
    extends: new BasePage(),
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {}, // 查询参数
            total:0,
            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                return usersWechat(requestParameters).then((res) => {
                 this.total = res.data?.total;
                return { code: 200, data: res.data?.list, total: res.data?.total }
                })
            },
            loading:false
        }
    },
    methods: {
        // 搜索
     isNull(value) {
        if (value === null) {
            return true;

        } else {
            return false;
        }

    },
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
        getType(type){
           let arr = ['公司用户','分包商','业主'];
           let flag = this.isNull(type);
           let name = '';
           name = !flag && arr[type];
           return name;
        },
        // 操作栏
        handleManage(record) {
          let that = this;
          this.$confirm({
          title: '温馨提示',
          content: `确认要解绑？`,
          okText: '确认',
          cancelText: '关闭',
          onOk() {
            that.unbund(record.userId)
          },
         onCancel: async () => {

        }
        })
        },
       async unbund(id){
          this.loading = true;
          let data = await deleteUserAndWechatByUserId({userId:id});
          this.loading = false;
          if(data.code*1!==500){
               this.$message.success('解绑成功')
               this.$refs.table.refresh(true)
          }
        }
    },
   created(){
    }
}
</script>
